[SQL][DML] Resolve Path Based Tables for both Reads and Writes#56039
[SQL][DML] Resolve Path Based Tables for both Reads and Writes#56039andreaschat-db wants to merge 19 commits into
Conversation
7a0af9a to
bf43ee1
Compare
|
Is this PR aiming for 4.2? |
Yes. It is an important fix for the DSv2 Transaction API. |
bf43ee1 to
1454dca
Compare
|
@aokolnychyi @andreaschat-db |
| * resolution. | ||
| */ | ||
| def supportsCatalogOptionsResolver(conf: SQLConf): DataSourceCatalogResolver = | ||
| (nameParts: Seq[String]) => |
There was a problem hiding this comment.
Should we attempt to do this only if we have 2 name parts?
We are talking about SQL on file scenarios, right?
There was a problem hiding this comment.
Do we care about spark.sql.runSQLonFiles? See ResolveSQLOnFile.
There was a problem hiding this comment.
Should we attempt to do this only if we have 2 name parts?
We are talking about SQL on file scenarios, right?
Yes these are SQL on file scenarios. The 2 name part sounds like a limitation of v1? IIUC in v2 dataframes we do not have such restriction. I guess the connector can decided how to handle it in extractCatalog/extractIdentifier?
Do we care about spark.sql.runSQLonFiles? See ResolveSQLOnFile
I added the sentinel.
| // identifier head, fall through to currentCatalog and let later analysis raise | ||
| // table-not-found. This matches the v1 file-format precedence (catalog first, | ||
| // path-based as fallback). | ||
| Option(catalogManager.catalogAndIdentForDataSource(nameParts)).flatten match { |
There was a problem hiding this comment.
I think this introduces a slight but problematic behavior change.
Say a user has a database named delta in their session catalog with a table orders.
SELECT * FROM delta.orders
Before: resolves to (session_catalog, ns=["delta"], name="orders") → finds the table correctly.
After: if the delta data source implements SupportsCatalogOptions, the SCO resolver intercepts, calls extractIdentifier with options derived from {"path": "orders"}, and routes to whatever catalog extractCatalog returns.
It seem like we should only pick the SQL on file approach if we KNOW / TEST that the current catalog can't resolve the requested namespace / identifier pair.
There was a problem hiding this comment.
Yes thank you. I fixed the resolution order.
|
I think this one is a blocker because we introduced partial SQL on file support in DSv2 that is incorrect, not only within the transaction itself. |
|
@huaxingao @andreaschat-db, I spent two days thinking about this PR. The current implementation still has a correctness issue but I was not sure how to fix it. I have an idea I will try tomorrow and will update here. Sorry it is taking longer, it ended up being a tricky problem. |
|
Let me share my thoughts:
Do we actually have to teach Spark to resolve SQL on path in DSv2? In theory, connectors like Delta already override the session catalog ( |
|
If we can support SQL on path in custom session catalogs like |
|
@andreaschat-db, what do you think? Can we support SQL on path on the Delta side? If we do that, we can start transactions pretty easily as I assume We already have |
My understanding is that yes we can do this on the connector (Delta) side. The requirement is that for path based tables the current catalog needs to be a transactional catalog that can also understand the path. IIUC this is consistent today with how delta works. If the current catalog is set to a non-delta catalog, delta paths won't work. The idea in this PRs was to have a more consistent handling of paths in Spark since we are already doing this in Dataframes. There are advantages of doing that (uniform handling across connectors, consistency with Dataframe handling, catalog extraction that independent of the current catalog etc) but I am ok of pushing this to the connector. Regarding the concerns above:
|
|
Yeah, I would be open to explore a better solution in Spark. What if we do this after 4.2? Can we for now remove the portions of the path-based resolution we added for transactions to unblock 4.2? |
|
This PR was succeeded by #56316. |
### What changes were proposed in this pull request? Current implementation for path based tables in SQL is partial. We are removing it for Spark 4.2. ### Why are the changes needed? The previous [attempt](#56039) to add path-based table support was halted due to concerns. For Spark 4.2 we are letting the connector handle it. ### Does this PR introduce _any_ user-facing change? No. Path based support in SQL was not yet released. ### How was this patch tested? Existing tests. ### Was this patch authored or co-authored using generative AI tooling? Claude Opus 4.7. Closes #56316 from andreaschat-db/dsv2TransactionRemoveSQLPathBasedSupport. Authored-by: Andreas Chatzistergiou <andreas.chatzistergiou@databricks.com> Signed-off-by: Anton Okolnychyi <aokolnychyi@apache.org>
### What changes were proposed in this pull request? Current implementation for path based tables in SQL is partial. We are removing it for Spark 4.2. ### Why are the changes needed? The previous [attempt](#56039) to add path-based table support was halted due to concerns. For Spark 4.2 we are letting the connector handle it. ### Does this PR introduce _any_ user-facing change? No. Path based support in SQL was not yet released. ### How was this patch tested? Existing tests. ### Was this patch authored or co-authored using generative AI tooling? Claude Opus 4.7. Closes #56316 from andreaschat-db/dsv2TransactionRemoveSQLPathBasedSupport. Authored-by: Andreas Chatzistergiou <andreas.chatzistergiou@databricks.com> Signed-off-by: Anton Okolnychyi <aokolnychyi@apache.org> (cherry picked from commit 42db152) Signed-off-by: Anton Okolnychyi <aokolnychyi@apache.org>
### What changes were proposed in this pull request? Current implementation for path based tables in SQL is partial. We are removing it for Spark 4.2. ### Why are the changes needed? The previous [attempt](#56039) to add path-based table support was halted due to concerns. For Spark 4.2 we are letting the connector handle it. ### Does this PR introduce _any_ user-facing change? No. Path based support in SQL was not yet released. ### How was this patch tested? Existing tests. ### Was this patch authored or co-authored using generative AI tooling? Claude Opus 4.7. Closes #56316 from andreaschat-db/dsv2TransactionRemoveSQLPathBasedSupport. Authored-by: Andreas Chatzistergiou <andreas.chatzistergiou@databricks.com> Signed-off-by: Anton Okolnychyi <aokolnychyi@apache.org> (cherry picked from commit 42db152) Signed-off-by: Anton Okolnychyi <aokolnychyi@apache.org>
|
The alternative PR has been merged into master, branch-4.x, and branch-4.2. Thanks! |
What changes were proposed in this pull request?
This PR fixes an issue where we would only correctly resolve path based tables if they were the target of transactional writes. The DataSource catalog resolution is being moved to
CatalogAndIdentifierso it can by used for both the target of the transactional write as well as the any other tables read. The approach maintains exactly the same semantics as the Dataframe path based identifier resolution.Why are the changes needed?
The catalog needs to be resolved correctly for all path based tables participating in a transactional write. This includes both the target as well as any other tables read. Without this fix, any scan on path-based tables would miss the configured catalog and would fall back to the session catalog.
Furthermore, in DSv2 transactions it is important to restrict all participating tables to a single catalog. This allows the single transactional catalog to track all reads and predicates that are relevant to the transaction.
Does this PR introduce any user-facing change?
Yes. Path based tables are now correctly resolved for both read and write operations.
How was this patch tested?
Added new tests.
Was this patch authored or co-authored using generative AI tooling?
Claude Sonnet 4.6.